package com.atxiao.controller;

import com.atxiao.common.R;
import com.atxiao.util.ImageUtil;
import com.atxiao.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class FileController {
    @Value("${file.path}")
   public String dirpath;

    /**
     * 文件上传
     * ResponseBean类 是我自定义的全局响应集合。可根据自己具体情况调整变更
     * @param file
     * @return
     */
    @RequestMapping(value = {"fileUpload"}, method = RequestMethod.POST)
    public Map<String,String> fileUpload(MultipartFile file) {
        HashMap<String, String> map1 = new HashMap<>();
        if (file == null) {
//            return ResponseBean.error(500,"请重新选择提交文件！");
            map1.put("msg","请重新选择提交文件");
            return map1;
        }
        Map<String, String> map = ImageUtil.uploadFile("lxxMerchant", file);

//        return ResponseBean.success(map);
        return map;
    }

//    @ApiOperation(value = "图片上传", notes = "图片上传")
    @PostMapping(value = "uploadCommodity")
    public List<Map<String,Object>> uploadImg(@RequestParam("file") List<MultipartFile> fileList, HttpServletRequest request) {
//        new UploadUtil()
//        return R.ok(appBasicServiceImpl.uploadImg(fileList, request));
        //存储的目标地址'
//        ArrayList<Map<String, Object>> list = new ArrayList<>();
//        String dirpath="D:\\data\\file\\xy\\web\\lxxMerchant\\";
        List<Map<String, Object>> list = UploadUtil.upload(fileList, request, dirpath);
//        list.add(map);
        return list;
    }


}
